<?php
/**
 * Created by PhpStorm.
 * User: 图图
 * Date: 2021-12-20
 * Time: 9:56
 */

namespace app\common\model;

use app\user\model\User;
use think\Db;
use think\Model as ThinkModel;

//银行列表模型
class Userphoto extends ThinkModel
{
    protected $name = 'qt_user_photo';
    protected $pk = 'id';
    protected $autoWriteTimestamp = true;


    /***
     * @param $user_id
     * @param $page
     * @param $limit
     * @return Userphoto[]|\think\Collection
     * 获取用户相册列表
     */
    public  function getlist($user_id,$page,$limit){
        $list=$this->where('user_id',$user_id)
            ->page($page,$limit)
            ->order('create_time','desc')
            ->select()->each(function ($item){
                $item['img']=get_img_path($item['images']);
                $item['author']= Db::name('qt_users')->where('id',$item['user_id'])->value('real_name');
                return $item;
            });
        return $list;
    }

    /**
     * @param $user_id
     * @param $images
     * @return bool
     * 添加相册
     */
    public  function addphoto($user_id,$images){
        if(empty($images)){
            return false;
        }
        $info['user_id']=$user_id;
        $info['images']=$images;
        $info['create_times']=time();
        if($this->create($info)){
            return true;
        }else{
            return false;
        }
    }

    /**
     * @param $user_id
     * @param $id
     * @return bool
     * @throws \Exception
     * 删除相册
     */
    public  function deletephoto($id){
        if(empty($id)){
            return false;
        }
        if($this->where('id',$id)->delete()){
            return true;
        }else{
            return false;
        }
    }
}